/*****************************************************************
Copyright (c) 2011 - 2017 Qualcomm Technologies International, Ltd.

PROJECT
    source
    
FILE NAME
    source_volume.c

DESCRIPTION
    Volume handling.
    
*/
/* VM headers */
#include <bdaddr.h>

 
/* header for this file */
#include "source_volume.h"
/* application header files */
#include "source_debug.h" 
#include "source_aghfp.h"
#include "source_audio.h"
#include "source_avrcp.h"
/* profile/library headers */

#ifdef DEBUG_VOLUME
    #define VOLUME_DEBUG(x) DEBUG(x)
#else
    #define VOLUME_DEBUG(x)
#endif

/* structure holding the volume levels */
typedef struct
{
    uint8 mic_vol_usb;
    uint8 mic_vol_analog;
    uint8 speaker_vol_usb;
    uint8 speaker_vol_analog;
    bool mic_mute;
    bool speaker_mute;
} VOLUME_DATA_T;

static VOLUME_DATA_T VOLUME_RUNDATA;

    
/***************************************************************************
Functions
****************************************************************************
*/

/****************************************************************************
NAME    
    volume_initialise

DESCRIPTION
    Initialise the volume levels.
*/
void volume_initialise(void)
{
    VOLUME_RUNDATA.speaker_vol_analog = VOLUME_SPEAKER_DEFAULT;
    VOLUME_RUNDATA.speaker_vol_usb = VOLUME_SPEAKER_USB_DEFAULT;
}

/****************************************************************************
NAME    
    volume_mute_mic

DESCRIPTION
    Updates the mic mute state.
*/
void volume_mute_mic(bool mute)
{
    VOLUME_RUNDATA.mic_mute = mute;
    VOLUME_DEBUG(("VOL: MIC Mute status[%d]\n", mute)); 
}

uint8 volume_get_speaker_volume(VOL_TYPE_T type)
{
    if(type == VOL_TYPE_USB)
    {
        return VOLUME_RUNDATA.speaker_vol_usb;
    }
    else if(type == VOL_TYPE_ANALOG)
    {
        return VOLUME_RUNDATA.speaker_vol_analog;
    }
    else
    {
        return 0;
    }
}

void volume_set_speaker_volume(uint8 speaker_vol, VOL_TYPE_T type)
{
    switch(type)
    {
    case VOL_TYPE_USB:
        VOLUME_RUNDATA.speaker_vol_usb = speaker_vol;
        break;
    case VOL_TYPE_ANALOG:
        VOLUME_RUNDATA.speaker_vol_analog = speaker_vol;
        break;
    case VOL_TYPE_BOTH:
        VOLUME_RUNDATA.speaker_vol_analog = speaker_vol;
        VOLUME_RUNDATA.speaker_vol_usb = speaker_vol;
        break;
    }
}
/****************************************************************************
NAME    
    volume_get_mic_volume -

DESCRIPTION
      Gets the mic volume 

RETURNS
    The current mic volume 
*/
uint8 volume_get_mic_volume(void)
{
    return VOLUME_RUNDATA.mic_vol_usb;
}
/****************************************************************************
NAME    
    volume_set_mic_volume -

DESCRIPTION
     Sets the mic volume 

RETURNS
    void
*/
void volume_set_mic_volume(uint8 mic_vol)
{
    VOLUME_RUNDATA.mic_vol_usb = mic_vol;
}
/****************************************************************************
NAME    
    volume_get_micmute -

DESCRIPTION
      Gets the Mic Mute variable.

RETURNS
    TRUE, if the mic mute is enabled.
    FALSE, if otherwise
*/
bool volume_get_micmute(void)
{
    return VOLUME_RUNDATA.mic_mute;
}
/****************************************************************************
NAME    
    volume_get_speaker_mute - 

DESCRIPTION
     Gets the Speaker Mute variable

RETURNS
    TRUE, if the speaker mute is enabled.
    FALSE, if otherwise
*/
bool volume_get_speaker_mute(void)
{
    return VOLUME_RUNDATA.speaker_mute;
}

